/**
 * 
 */
package stationGUI;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

/**
 * @author Ian Gardner
 *
 */
public class ColorChooser {
  String name;
  Color color;
  Rectangle2D.Float r;
  
  /**
   * Initilize this color choosers color and the corresponding string
   * 
   * @param s - the color's name
   * @param c - the color
   */
  public ColorChooser(String s,Color c) {
    name = s;
    color = c;
    r=new Rectangle2D.Float();
  }
  
  /**
   * Sets the frame for where this box will be displayed. No altering of the
   * passed in data is done. This means that this ColorChooser's bottom left
   * corner will be placed at x,y and its width and height will be w,h.
   * 
   * @param x - x position of the bottom left corner
   * @param y - y position of the bottom left corner
   * @param w - width
   * @param h - height
   */
  public void set(int x,int y,int w,int h) {
    r.setFrame(x,y,w,h);
  }
 
  /**
   * Paints the ColorChooser using the existing settings. Should be called
   * through the paint() method of other applications.
   * 
   * @param g - the graphics instance from calling paint() method
   */
  public void paintColorChooser(Graphics2D g,Color c){
    //if this color is currently selected
    if(c==color) paintSelectedColorChooser(g);
    
    else {//paint the color chooser using the current graphic settings
      g.setColor(color);
      g.fill(r);
      
      g.setColor(Color.WHITE);
      g.drawString(name,r.x,r.y+r.height*4/5);
    }
  }

  /**
   * Paints the selected ColorChooser using the existing settings. Should be 
   * called through the paint() method of other applications.
   * 
   * @param g - the graphics instance from calling paint() method
   */
  public void paintSelectedColorChooser(Graphics2D g) {
    //paint the selected color chooser using the current graphic settings
    g.setColor(Color.WHITE);
    g.fill(r);
    
    g.setColor(color);
    g.drawString(name,r.x,r.y+r.height*4/5);
  }
}
